package etxt2db.utils;

/**
 * Container of a triple of generic objects.
 * <p>
 * @param <A>	the class of the first object
 * @param <B>	the class of the second object
 * @param <C>	the class of the third object
 */
public class Triple<A,B,C> {
	
	private A first;
	private B second;
	private C third;
	
	/**
	 * Constructs a container of a pair of generic objects.
	 * <p>
	 * @param first		the first object of the pair
	 * @param second	the second object of the pair
	 * @param third		the third object of the pair
	 */
	public Triple(A first, B second, C third) {
		this.first = first;
		this.second = second;
		this.third = third;
	}
	
	/**
	 * @param first	the first object to set
	 */
	public void setFirst(A first) {
		this.first = first;
	}
	
	/**
	 * @return	the first object of the pair
	 */
	public A getFirst() {
		return first;
	}
	
	/**
	 * @param second	the second object to set
	 */
	public void setSecond(B second) {
		this.second = second;
	}
	
	/**
	 * @return	the second object of the pair
	 */
	public B getSecond() {
		return second;
	}
	
	/**
	 * @param third	the third object to set
	 */
	public void setThird(C third) {
		this.third = third;
	}
	
	/**
	 * @return	the third object of the pair
	 */
	public C getThird() {
		return third;
	}
	
	@Override
	public int hashCode(){
		return (first.hashCode()+second.hashCode()+third.hashCode())/3;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Triple<?,?,?>){
			return first.equals(((Triple<?,?,?>) obj).getFirst()) && second.equals(((Triple<?,?,?>) obj).getSecond()) && third.equals(((Triple<?,?,?>) obj).getThird());
		}
		return false;
	}
	
	@Override
	public String toString(){
		return "(" + first.toString() + "," + second.toString() + "," + third.toString() + ")";
	}
}
